class DequeObject(object):
    def __init__(self, val=0, pre = None, next=None):
        self.val = val
        self.pre = pre
        self.next = next

class MyCircularDeque(object):
    def __init__(self, k):
        """
        :type k: int
        """
        self.max_size = k
        self.size = 0

        self.head = None
        self.tail = None


    def insertFront(self, value):
        """
        :type value: int
        :rtype: bool
        """
        if (self.size == self.max_size):
            return False
        new_head = DequeObject(value, None, self.head)
        if self.size == 0:
            self.head = new_head
            self.tail = new_head
        else:
            self.head.pre = new_head
            self.head = new_head
        self.size = self.size + 1

        return True


    def insertLast(self, value):
        """
        :type value: int
        :rtype: bool
        """
        if (self.size == self.max_size):
            return False   
        new_tail = DequeObject(value, self.tail, None)
        if self.size == 0:
            self.head = new_tail
            self.tail = new_tail
        else:
            self.tail.next = new_tail
            self.tail = new_tail
        self.size = self.size + 1
        return True


    def deleteFront(self):
        """
        :rtype: bool
        """
        if (self.size == 0):
            return False

        if self.size == 1:
            self.head = None
            self.tail = None
        else:
            self.head.next.pre = None
            self.head = self.head.next
            self.head.pre = None
        self.size = self.size - 1
    
        return True


    def deleteLast(self):
        """
        :rtype: bool
        """
        if (self.size == 0):
            return False

        if self.size == 1:
            self.head = None
            self.tail = None
        else:
            self.tail.pre.next = None
            self.tail = self.tail.pre
            self.tail.next = None
        self.size = self.size - 1

        return True


    def getFront(self):
        """
        :rtype: int
        """
        if (self.size == 0):
            return -1
        return self.head.val


    def getRear(self):
        """
        :rtype: int
        """
        if (self.size == 0):
            return -1
        return self.tail.val


    def isEmpty(self):
        """
        :rtype: bool
        """
        return self.size == 0


    def isFull(self):
        """
        :rtype: bool
        """
        return self.size == self.max_size

